#ifndef ASTARPATHFINDER_H
#define ASTARPATHFINDER_H

#include <QPoint>
#include <vector>

class AStarPathfinder {
public:
    AStarPathfinder(const std::vector<std::vector<int>>& map);
    std::vector<QPoint> findPath(const QPoint& start, const QPoint& end);

private:
    struct Node {
        QPoint position;
        int gCost; // 从起点到当前节点的实际代价
        int hCost; // 从当前节点到终点的预估代价
        int fCost; // fCost = gCost + hCost
        Node* parent;

        Node(const QPoint& pos, int g, int h, Node* p = nullptr)
            : position(pos), gCost(g), hCost(h), fCost(g + h), parent(p) {}
    };

    std::vector<std::vector<int>> map;
    int heuristic(const QPoint& a, const QPoint& b);
    bool isValid(const QPoint& point);
    std::vector<Node*> getNeighbors(const Node* node);
};

#endif // ASTARPATHFINDER_H
